#! /usr/bin/python3
#
# memleak   Trace and display outstanding allocations to detect
#           memory leaks in user-mode processes and the kernel.
#
# USAGE: memleak [-h] [-p PID] [-t] [-a] [-o OLDER] [-c COMMAND]
#                [--combined-only] [--wa-missing-free] [-s SAMPLE_RATE]
#                [-T TOP] [-z MIN_SIZE] [-Z MAX_SIZE] [-O OBJ]
#                [interval] [count]
#
# Licensed under the Apache License, Version 2.0 (the "License")
# Copyright (C) 2016 Sasha Goldshtein.

from __future__ import annotations
from bcc import BPF
from time import sleep
from datetime import datetime
import resource
import argparse
import subprocess
import os
import sys
from typing import Dict, Tuple, Sequence, List, Any
import json
import traceback
from ctypes import *
import re


bpf_source = ''

rootPath = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(rootPath, "mmap.test.c"), 'r') as f:
        bpf_source = f.read()
        bpf_source += '\n'

with open(os.path.join(rootPath, "mmap.test.out.c"), 'w') as f:
        f.write(bpf_source)

bpf = BPF(text=bpf_source)

while True:
        print('wann ')
        print(bpf.trace_fields())
